package org.social.db.bean;

import org.social.db.cache.NoticeCache;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.social.db.StaticResource.NoticeResource.*;
import static org.social.db.StaticResource.NoticeResource.*;
/**
 * 通知
 */
public class Notice extends BasePojo<Notice> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[1];
	
	/**
	* id
	*/
	private int id;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 渠道
	*/
	private int channel;
	
	/**
	* 渠道appId
	*/
	private int channelAppId;
	
	/**
	* 序号
	*/
	private int idx;
	
	/**
	* 类型
	*/
	private int type;
	
	/**
	* 标签
	*/
	private int tag;
	
	/**
	* 标题
	*/
	private String title;
	
	/**
	* 内容
	*/
	private String content;
	
	/**
	* 附加参数（json格式）
	*/
	private String param;
	
	/**
	* 图片
	*/
	private String contextImg;
	
	/**
	* 开始时间
	*/
	private java.util.Date startTime;
	
	/**
	* 结束时间
	*/
	private java.util.Date endTime;
	
	
	@Deprecated
	public static Notice builder() {
		Notice notice = new Notice();
		return notice;
	}
	
	@Deprecated
	public Notice() {
		super();
	}
	
	public Notice(int id, int channel, int channelAppId, int idx, int type, int tag, String title, String content, String param, String contextImg, java.util.Date startTime, java.util.Date endTime) {
		super();
		this.id = id;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.channel = channel;
		this.channelAppId = channelAppId;
		this.idx = idx;
		this.type = type;
		this.tag = tag;
		this.title = title;
		this.content = content;
		this.param = param;
		this.contextImg = contextImg;
		this.startTime = startTime;
		this.endTime = endTime;
	}
	
	/**
	 * id
	 */
	public int getId() {return id;}
	
	/**
	 * id
	 */
	public Notice setId(int id) {this.id = id;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Notice setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Notice setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 渠道
	 */
	public int getChannel() {return channel;}
	
	/**
	 * 渠道
	 */
	public Notice setChannel(int channel) {this.channel = channel;return this;}
	
	/**
	 * 渠道appId
	 */
	public int getChannelAppId() {return channelAppId;}
	
	/**
	 * 渠道appId
	 */
	public Notice setChannelAppId(int channelAppId) {this.channelAppId = channelAppId;return this;}
	
	/**
	 * 序号
	 */
	public int getIdx() {return idx;}
	
	/**
	 * 序号
	 */
	public Notice setIdx(int idx) {this.idx = idx;return this;}
	
	/**
	 * 类型
	 */
	public int getType() {return type;}
	
	/**
	 * 类型
	 */
	public Notice setType(int type) {this.type = type;return this;}
	
	/**
	 * 标签
	 */
	public int getTag() {return tag;}
	
	/**
	 * 标签
	 */
	public Notice setTag(int tag) {this.tag = tag;return this;}
	
	/**
	 * 标题
	 */
	public String getTitle() {return title;}
	
	/**
	 * 标题
	 */
	public Notice setTitle(String title) {this.title = title;return this;}
	
	/**
	 * 内容
	 */
	public String getContent() {return content;}
	
	/**
	 * 内容
	 */
	public Notice setContent(String content) {this.content = content;return this;}
	
	/**
	 * 附加参数（json格式）
	 */
	public String getParam() {return param;}
	
	/**
	 * 附加参数（json格式）
	 */
	public Notice setParam(String param) {this.param = param;return this;}
	
	/**
	 * 图片
	 */
	public String getContextImg() {return contextImg;}
	
	/**
	 * 图片
	 */
	public Notice setContextImg(String contextImg) {this.contextImg = contextImg;return this;}
	
	/**
	 * 开始时间
	 */
	public java.util.Date getStartTime() {return startTime;}
	
	/**
	 * 开始时间
	 */
	public Notice setStartTime(java.util.Date startTime) {this.startTime = startTime;return this;}
	
	/**
	 * 结束时间
	 */
	public java.util.Date getEndTime() {return endTime;}
	
	/**
	 * 结束时间
	 */
	public Notice setEndTime(java.util.Date endTime) {this.endTime = endTime;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.createDate;
        values[2] = this.modifiedDate;
        values[3] = this.channel;
        values[4] = this.channelAppId;
        values[5] = this.idx;
        values[6] = this.type;
        values[7] = this.tag;
        values[8] = this.title;
        values[9] = this.content;
        values[10] = this.param;
        values[11] = this.contextImg;
        values[12] = this.startTime;
        values[13] = this.endTime;
        return values;
	}
	
	public Notice deepCopy(){
		Notice notice = null;
		try {
			notice = (Notice) super.clone();
		    notice.setCreateDate(ToolCopy.copyObject(this.createDate));
		    notice.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    notice.setStartTime(ToolCopy.copyObject(this.startTime));
		    notice.setEndTime(ToolCopy.copyObject(this.endTime));
		    // 克隆索引
		    notice.indexValues = ArrayUtils.clone(indexValues);
			return notice;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return notice;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.createDate);
        map.put(keys[2], this.modifiedDate);
        map.put(keys[3], this.channel);
        map.put(keys[4], this.channelAppId);
        map.put(keys[5], this.idx);
        map.put(keys[6], this.type);
        map.put(keys[7], this.tag);
        map.put(keys[8], this.title);
        map.put(keys[9], this.content);
        map.put(keys[10], this.param);
        map.put(keys[11], this.contextImg);
        map.put(keys[12], this.startTime);
        map.put(keys[13], this.endTime);
        return map;
    }
    
    protected Notice createForMap(Object[] keys,Map map){
   		this.id = (int)map.get(keys[0]);
   		this.createDate = (java.util.Date)map.get(keys[1]);
   		this.modifiedDate = (java.util.Date)map.get(keys[2]);
   		this.channel = (int)map.get(keys[3]);
   		this.channelAppId = (int)map.get(keys[4]);
   		this.idx = (int)map.get(keys[5]);
   		this.type = (int)map.get(keys[6]);
   		this.tag = (int)map.get(keys[7]);
   		this.title = (String)map.get(keys[8]);
   		this.content = (String)map.get(keys[9]);
   		this.param = (String)map.get(keys[10]);
   		this.contextImg = (String)map.get(keys[11]);
   		this.startTime = (java.util.Date)map.get(keys[12]);
   		this.endTime = (java.util.Date)map.get(keys[13]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.createDate);
        obj.put(keys[2], this.modifiedDate);
        obj.put(keys[3], this.channel);
        obj.put(keys[4], this.channelAppId);
        obj.put(keys[5], this.idx);
        obj.put(keys[6], this.type);
        obj.put(keys[7], this.tag);
        obj.put(keys[8], this.title);
        obj.put(keys[9], this.content);
        obj.put(keys[10], this.param);
        obj.put(keys[11], this.contextImg);
        obj.put(keys[12], this.startTime);
        obj.put(keys[13], this.endTime);
        return obj;
    }
    
    protected Notice createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getIntValue(keys[0]);
	    this.createDate = obj.getDate(keys[1]);
	    this.modifiedDate = obj.getDate(keys[2]);
	    this.channel = obj.getIntValue(keys[3]);
	    this.channelAppId = obj.getIntValue(keys[4]);
	    this.idx = obj.getIntValue(keys[5]);
	    this.type = obj.getIntValue(keys[6]);
	    this.tag = obj.getIntValue(keys[7]);
	    this.title = obj.getString(keys[8]);
	    this.content = obj.getString(keys[9]);
	    this.param = obj.getString(keys[10]);
	    this.contextImg = obj.getString(keys[11]);
	    this.startTime = obj.getDate(keys[12]);
	    this.endTime = obj.getDate(keys[13]);
        return this;
    }
    
    
    public Notice createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getInt(SOURCE_COLUMN_NAMES[0]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[1]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[2]);
	    this.channel = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.channelAppId = rs.getInt(SOURCE_COLUMN_NAMES[4]);
	    this.idx = rs.getInt(SOURCE_COLUMN_NAMES[5]);
	    this.type = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    this.tag = rs.getInt(SOURCE_COLUMN_NAMES[7]);
	    this.title = rs.getString(SOURCE_COLUMN_NAMES[8]);
	    this.content = rs.getString(SOURCE_COLUMN_NAMES[9]);
	    this.param = rs.getString(SOURCE_COLUMN_NAMES[10]);
	    this.contextImg = rs.getString(SOURCE_COLUMN_NAMES[11]);
	    this.startTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[12]);
	    this.endTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[13]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeInt(this.id);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeInt(this.channel);
	    byteBuf.writeInt(this.channelAppId);
	    byteBuf.writeInt(this.idx);
	    byteBuf.writeInt(this.type);
	    byteBuf.writeInt(this.tag);
	    byteBuf.writeString(this.title);
	    byteBuf.writeString(this.content);
	    byteBuf.writeString(this.param);
	    byteBuf.writeString(this.contextImg);
	    byteBuf.writeDate(this.startTime);
	    byteBuf.writeDate(this.endTime);
    }
	
	protected Notice readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.channel = byteBuf.readInt(null);
	    this.channelAppId = byteBuf.readInt(null);
	    this.idx = byteBuf.readInt(null);
	    this.type = byteBuf.readInt(null);
	    this.tag = byteBuf.readInt(null);
	    this.title = byteBuf.readString(null);
	    this.content = byteBuf.readString(null);
	    this.param = byteBuf.readString(null);
	    this.contextImg = byteBuf.readString(null);
	    this.startTime = byteBuf.readDate(null);
	    this.endTime = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Notice insert(){
    	return NoticeCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Notice update(){
    	return NoticeCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return NoticeCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Notice insertAndFlush(){
    	return NoticeCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Notice updateAndFlush(){
    	return NoticeCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return NoticeCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Notice syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((int)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}